// var i;
// var AL_GAME_HUA_i18nMgr = require("./AL_GAME_HUA_i18nMgr");
// var AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
// var AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
// var AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
// var AL_GAME_HUA_GoodsConfig = require("./AL_GAME_HUA_GoodsConfig");
// var AL_GAME_HUA_CurrencyData = require("./AL_GAME_HUA_CurrencyData");
// var d = cc._decorator;
// var h = d.ccclass;
// var _ = d.property;
// var P = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.bg = null;
//         t.spriteframe_bg_list = [];
//         t.color_title_list = [];
//         t.icon = null;
//         t.label_number = null;
//         t.price_node = null;
//         t.node_video = null;
//         t.label_button_price = null;
//         t.title_label = null;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.zhixing_chushihua_chuli = function (e) {
//         var t = this;
//         this.bg.spriteFrame = this.spriteframe_bg_list[e.bgId];
//         this.label_number.getComponent(cc.LabelOutline).color = this.color_title_list[e.bgId];
//         var n = e.goodInfo;
//         var o = e.count;
//         var i = e.price;
//         this.title_label.string = AL_GAME_HUA_i18nMgr.i18nMgr._huoqu_biaoqian(n.name);
//         this.label_number.string = "x" + o.toString();
//         n.id == AL_GAME_HUA_GoodsConfig.GoodsId.gold
//             ? (this.price_node.active = !1)
//             : ((this.price_node.active = AL_GAME_HUA_GameConst.GameConst.getInstance().coin_buy_prop_enabled),
//               (this.label_button_price.string = i.toString()));
//         AL_GAME_HUA_GoodsConfig.GoodsConfig.getInstance()
//             .jiazai_tubiao_icon(n.id)
//             .then(function (e) {
//                 if (cc.isValid(t)) {
//                     t.icon.spriteFrame = e;
//                     t.icon.addAutoReleaseAssets(e);
//                     AL_GAME_HUA_Common.Common.uniform_scale(t.icon, 100, 100);
//                 }
//             });
//         this.node_video.on(
//             "touchend",
//             function () {
//                 AL_GAME_HUA_Common.Common.showVideo({
//                     success: function (t) {
//                         e.onBuy(t.type);
//                     }
//                 });
//             },
//             this
//         );
//         this.price_node.on(
//             "touchend",
//             function () {
//                 AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().shiyong_huobi({
//                     type: AL_GAME_HUA_CurrencyData.CurrencyType.COIN,
//                     num: i
//                 }).result
//                     ? e.onBuy(0)
//                     : AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_tishi_jiedian_mianban({
//                           str: "金币不足"
//                       });
//             },
//             this
//         );
//     };
//     __decorate([_(cc.Sprite)], t.prototype, "bg", void 0);
//     __decorate([_([cc.SpriteFrame])], t.prototype, "spriteframe_bg_list", void 0);
//     __decorate([_([cc.Color])], t.prototype, "color_title_list", void 0);
//     __decorate([_(cc.Sprite)], t.prototype, "icon", void 0);
//     __decorate([_(cc.Label)], t.prototype, "label_number", void 0);
//     __decorate([_(cc.Node)], t.prototype, "price_node", void 0);
//     __decorate([_(cc.Node)], t.prototype, "node_video", void 0);
//     __decorate([_(cc.Label)], t.prototype, "label_button_price", void 0);
//     __decorate([_(cc.Label)], t.prototype, "title_label", void 0);
//     return __decorate([h], t);
// })(cc.Component);
// exports.default = P;


/**
 * 游戏场景初始化类
 */
// var AL_GAME_HUA_i18nMgr = require("./AL_GAME_HUA_i18nMgr");
// var AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
// var AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
// var AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
// var AL_GAME_HUA_GoodsConfig = require("./AL_GAME_HUA_GoodsConfig");
// var AL_GAME_HUA_CurrencyData = require("./AL_GAME_HUA_CurrencyData");

// var decorator = cc._decorator;
// var classDecorator = decorator.ccclass;
// var property = decorator.property;

// /**
//  * 商品显示类
//  * 负责处理商品的视觉表现和交互逻辑
//  */
// var ProductDisplay = (function (BaseComponent) {
    
//     // 子类构造函数
//     function ProductDisplay() {
//         // 调用父类构造函数
//         var instance = (null !== BaseComponent && BaseComponent.apply(this, arguments)) || this;

//         // 初始化成员变量
//         instance.bg = null;
//         instance.spriteframe_bg_list = [];
//         instance.color_title_list = [];
//         instance.icon = null;
//         instance.label_number = null;
//         instance.price_node = null;
//         instance.node_video = null;
//         instance.label_button_price = null;
//         instance.title_label = null;

//         return instance;
//     }
//     __extends(ProductDisplay, BaseComponent);

//     /**
//      * 初始化方法
//      * @param {object} config 商品配置信息
//      */
//     ProductDisplay.prototype.zhixing_chushihua_chuli = function (config) {
//         var self = this;

//         // 设置背景图片
//         self.bg.spriteFrame = self.spriteframe_bg_list[config.bgId];

//         // 设置数字标签的颜色
//         self.label_number.getComponent(cc.LabelOutline).color = self.color_title_list[config.bgId];

//         var goodInfo = config.goodInfo;
//         var count = config.count;
//         var price = config.price;

//         // 设置商品名称
//         self.title_label.string = AL_GAME_HUA_i18nMgr.i18nMgr._huoqu_biaoqian(goodInfo.name);

//         // 设置数量标签
//         self.label_number.string = "x" + count.toString();

//         // 设置价格节点的显示
//         goodInfo.id == AL_GAME_HUA_GoodsConfig.GoodsId.gold
//             ? (self.price_node.active = false)
//             : ((self.price_node.active = AL_GAME_HUA_GameConst.GameConst.getInstance().coin_buy_prop_enabled),
//                (self.label_button_price.string = price.toString()));

//         // 加载商品图标
//         AL_GAME_HUA_GoodsConfig.GoodsConfig.getInstance()
//             .jiazai_tubiao_icon(goodInfo.id)
//             .then(function (spriteFrame) {
//                 if (cc.isValid(self)) {
//                     self.icon.spriteFrame = spriteFrame;
//                     self.icon.addAutoReleaseAssets(spriteFrame);
//                     AL_GAME_HUA_Common.Common.uniform_scale(self.icon, 100, 100);
//                 }
//             });

//         // 设置视频节点点击事件
//         self.node_video.on(
//             "touchend",
//             function () {
//                 AL_GAME_HUA_Common.Common.showVideo({
//                     success: function (result) {
//                         config.onBuy(result.type);
//                     }
//                 });
//             },
//             self
//         );

//         // 设置价格节点点击事件
//         self.price_node.on(
//             "touchend",
//             function () {
//                 AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().shiyong_huobi({
//                     type: AL_GAME_HUA_CurrencyData.CurrencyType.COIN,
//                     num: price
//                 }).result
//                     ? config.onBuy(0)
//                     : AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_tishi_jiedian_mianban({
//                           str: "金币不足"
//                       });
//             },
//             self
//         );
//     };

//     // 通过装饰器添加成员变量
//     __decorate([property(cc.Sprite)], ProductDisplay.prototype, "bg", void 0);
//     __decorate([property([cc.SpriteFrame])], ProductDisplay.prototype, "spriteframe_bg_list", void 0);
//     __decorate([property([cc.Color])], ProductDisplay.prototype, "color_title_list", void 0);
//     __decorate([property(cc.Sprite)], ProductDisplay.prototype, "icon", void 0);
//     __decorate([property(cc.Label)], ProductDisplay.prototype, "label_number", void 0);
//     __decorate([property(cc.Node)], ProductDisplay.prototype, "price_node", void 0);
//     __decorate([property(cc.Node)], ProductDisplay.prototype, "node_video", void 0);
//     __decorate([property(cc.Label)], ProductDisplay.prototype, "label_button_price", void 0);
//     __decorate([property(cc.Label)], ProductDisplay.prototype, "title_label", void 0);

//     return __decorate([classDecorator], ProductDisplay);
// })(cc.Component);

// // 导出ProductDisplay类
// exports.default = ProductDisplay;


// 引入依赖模块
const AL_GAME_HUA_i18nMgr = require("./AL_GAME_HUA_i18nMgr");
const AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
const AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
const AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
const AL_GAME_HUA_GoodsConfig = require("./AL_GAME_HUA_GoodsConfig");
const AL_GAME_HUA_CurrencyData = require("./AL_GAME_HUA_CurrencyData");

const { ccclass, property } = cc._decorator;

/**
 * 商品显示类
 * 负责处理商品的视觉表现和交互逻辑
 */
@ccclass
class ProductDisplay extends cc.Component {
    // 商品显示的背景图片
    @property(cc.Sprite)
    bg = null;

    // 背景图片的 SpriteFrame 数组
    @property([cc.SpriteFrame])
    spriteframe_bg_list = [];

    // 标题颜色数组
    @property([cc.Color])
    color_title_list = [];

    // 商品图标
    @property(cc.Sprite)
    icon = null;

    // 商品数量的标签
    @property(cc.Label)
    label_number = null;

    // 商品价格节点
    @property(cc.Node)
    price_node = null;

    // 视频节点
    @property(cc.Node)
    node_video = null;

    // 商品价格的标签
    @property(cc.Label)
    label_button_price = null;

    // 商品标题标签
    @property(cc.Label)
    title_label = null;

    /**
     * 初始化方法
     * @param {object} config 商品配置信息
     */
    zhixing_chushihua_chuli(config) {
        // 设置背景图片
        this.bg.spriteFrame = this.spriteframe_bg_list[config.bgId];

        // 设置数字标签的颜色
        const numLabelOutline = this.label_number.getComponent(cc.LabelOutline);
        numLabelOutline.color = this.color_title_list[config.bgId];

        const goodInfo = config.goodInfo;
        const count = config.count;
        const price = config.price;

        // 设置商品名称
        this.title_label.string = AL_GAME_HUA_i18nMgr.i18nMgr._huoqu_biaoqian(goodInfo.name);

        // 设置数量标签
        this.label_number.string = `x${count}`;

        // 设置价格节点的显示
        if (goodInfo.id === AL_GAME_HUA_GoodsConfig.GoodsId.gold) {
            this.price_node.active = false;
        } else {
            this.price_node.active = AL_GAME_HUA_GameConst.GameConst.getInstance().coin_buy_prop_enabled;
            this.label_button_price.string = price.toString();
        }

        // 加载商品图标
        AL_GAME_HUA_GoodsConfig.GoodsConfig.getInstance()
            .jiazai_tubiao_icon(goodInfo.id)
            .then((spriteFrame) => {
                if (cc.isValid(this)) {
                    this.icon.spriteFrame = spriteFrame;
                    this.icon.addAutoReleaseAssets(spriteFrame);
                    AL_GAME_HUA_Common.Common.uniform_scale(this.icon, 100, 100);
                }
            });

        // 设置视频节点点击事件
        this.node_video.on(
            "touchend",
            () => {
                AL_GAME_HUA_Common.Common.showVideo({
                    success: (result) => {
                        config.onBuy(result.type);
                    },
                });
            },
            this
        );

        // 设置价格节点点击事件
        this.price_node.on(
            "touchend",
            () => {
                const currencyResult = AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().shiyong_huobi({
                    type: AL_GAME_HUA_CurrencyData.CurrencyType.COIN,
                    num: price,
                }).result;

                if (currencyResult) {
                    config.onBuy(0);
                } else {
                    AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_tishi_jiedian_mianban({
                        str: "金币不足",
                    });
                }
            },
            this
        );
    }
}

// 导出 ProductDisplay 类
exports.default = ProductDisplay;
